package com.das.mechanic_base.adapter.processnew;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.bean.alone.AloneImageAndRecordBean;
import com.das.mechanic_base.bean.custrecord.CustomRecordListBean;
import com.das.mechanic_base.utils.X3StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：zhangM
 */
public class TransverseTitleAdapter extends RecyclerView.Adapter<TransverseTitleAdapter.MyTransverseTitleViewHolder> {

    private Context context;

    private List<CustomRecordListBean> mList;

    private boolean isSelect;

    public TransverseTitleAdapter(Context context) {
        this.context = context;
        mList = new ArrayList<>();
    }

    @Override
    public MyTransverseTitleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyTransverseTitleViewHolder(LayoutInflater.from(context).inflate(R.layout.transverse_title_adapter, parent, false));
    }

    /**
     *
     * @param mList
     * @param isSelects
     * true：自定义工序，除了根据图片是否上传还需要根据是否有名称来判断
     * false：标准工序，只根据是否上传图片来判断
     */
    public void setData(List<CustomRecordListBean> mList, boolean isSelects) {
        this.mList.clear();
        this.mList = mList;
        isSelect = isSelects;
        notifyDataSetChanged();

    }
    public void setData(List<CustomRecordListBean> mList, boolean isSelects,int item) {
        this.mList = mList;
        isSelect = isSelects;
        notifyItemChanged(item);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public void onBindViewHolder(@NonNull MyTransverseTitleViewHolder holder, int position) {

        holder.title_tv_select.setText(position + 1 + "");

        List<AloneImageAndRecordBean> imageBeans = mList.get(position).getMList();
        if (isSelect) {
            if (!X3StringUtils.isListEmpty(imageBeans) && !X3StringUtils.isEmpty(mList.get(position).getName())) {
                holder.title_tv_select.setTextColor(Color.parseColor("#ffffff"));
                holder.title_imge_select.setBackground(ContextCompat.getDrawable(context, R.drawable.x3_bg_fff_shape_ls));
            } else {
                holder.title_tv_select.setTextColor(Color.parseColor("#666666"));
                holder.title_imge_select.setBackground(ContextCompat.getDrawable(context, R.drawable.x3_bg_fff_shape));
            }
        } else {
            if (!X3StringUtils.isListEmpty(imageBeans)) {
                holder.title_tv_select.setTextColor(Color.parseColor("#ffffff"));
                holder.title_imge_select.setBackground(ContextCompat.getDrawable(context, R.drawable.x3_bg_fff_shape_ls));
            } else {
                holder.title_tv_select.setTextColor(Color.parseColor("#666666"));
                holder.title_imge_select.setBackground(ContextCompat.getDrawable(context, R.drawable.x3_bg_fff_shape));
            }
        }


        holder.item_on_rl.setOnClickListener(v -> iOnClickTake.getIOnClickSelectItem(position));
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }


    IOnClickSelectItem iOnClickTake;

    public void setIOnClickSelectItem(IOnClickSelectItem iOnClickTake) {
        this.iOnClickTake = iOnClickTake;
    }

    public interface IOnClickSelectItem {
        void getIOnClickSelectItem(int index);
    }


    class MyTransverseTitleViewHolder extends RecyclerView.ViewHolder {

        private RelativeLayout title_imge_select;
        private RelativeLayout item_on_rl;
        private TextView title_tv_select;

        public MyTransverseTitleViewHolder(@NonNull View itemView) {
            super(itemView);
            title_imge_select = itemView.findViewById(R.id.title_imge_select);
            title_tv_select = itemView.findViewById(R.id.title_tv_select);
            item_on_rl = itemView.findViewById(R.id.item_on_rl);
        }
    }

}
